<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RabbitMQ消息确认机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            font-family: 'Noto Serif SC', serif;
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 0;
            right: 0;
            background: #667eea;
            color: white;
            padding: 4px 12px;
            border-radius: 0 8px 0 8px;
            font-size: 12px;
            font-weight: 500;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
            transition: all 0.3s ease;
        }
        
        .feature-icon:hover {
            transform: rotate(10deg) scale(1.1);
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::after {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(0.8); opacity: 0.5; }
            50% { transform: scale(1.2); opacity: 0.8; }
        }
        
        .mermaid {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            margin: 30px 0;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 8px;
            width: 12px;
            height: 12px;
            background: #667eea;
            border-radius: 50%;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 15px;
            top: 20px;
            width: 2px;
            height: calc(100% + 10px);
            background: #e2e8f0;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-8">
        <div class="max-w-6xl mx-auto text-center relative z-10">
            <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                RabbitMQ消息确认机制
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                深入理解分布式消息队列的可靠性保障
            </p>
            <div class="flex justify-center space-x-8 text-sm">
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>高可靠性</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-sync-alt mr-2"></i>
                    <span>自动重试</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-check-double mr-2"></i>
                    <span>双向确认</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Introduction Section -->
    <div class="max-w-6xl mx-auto px-8 py-16">
        <div class="content-card rounded-2xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                随着分布式系统和消息中间件的广泛应用，如何确保消息能够可靠地从生产者发送到消费者，并且避免因网络波动、系统故障等原因导致消息丢失，已经成为我们设计和使用消息队列时必须解决的问题。
            </p>
            <p class="text-lg leading-relaxed text-gray-700">
                RabbitMQ作为一种流行的消息中间件，它提供了多种消息确认机制，能够有效地保证消息的可靠传递，并且支持不同场景下的容错与重试机制。
            </p>
        </div>

        <!-- Core Concepts Visualization -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8">核心概念关系图</h2>
            <div class="mermaid">
                graph TB
                    A[生产者 Producer] -->|发送消息| B[RabbitMQ Broker]
                    B -->|路由| C[Exchange 交换机]
                    C -->|绑定| D[Queue 队列]
                    D -->|投递| E[消费者 Consumer]
                    
                    A -.->|Publisher Confirm| B
                    E -.->|Consumer ACK| D
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Two Types of Confirmation -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon">
                    <i class="fas fa-paper-plane"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4" style="font-family: 'Noto Serif SC', serif;">
                    发布者确认
                </h3>
                <p class="text-gray-700 mb-4">
                    发布者确认（Publisher Confirm）是指生产者向RabbitMQ服务器发送消息后，RabbitMQ会给生产者一个确认信号，告知消息是否已经成功地写入到队列中。
                </p>
                <ul class="space-y-2 text-gray-600">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>异步确认机制，不阻塞消息发送</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>支持批量确认，提高性能</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>确保消息成功到达Broker</span>
                    </li>
                </ul>
            </div>
            
            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon">
                    <i class="fas fa-user-check"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4" style="font-family: 'Noto Serif SC', serif;">
                    消费者确认
                </h3>
                <p class="text-gray-700 mb-4">
                    消费者确认（Consumer Acknowledgment）是指当消费者从RabbitMQ队列中成功消费并处理一条消息后，消费者需要通过ack信号告知RabbitMQ这条消息已经成功处理。
                </p>
                <ul class="space-y-2 text-gray-600">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>手动/自动确认模式可选</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>支持消息重试机制</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                        <span>防止消息丢失</span>
                    </li>
                </ul>
            </div>
        </div>

        <!-- Message Flow Timeline -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8">消息确认流程</h2>
            <div class="timeline-item">
                <h4 class="font-bold text-lg mb-2">1. 消息发送</h4>
                <p class="text-gray-600">生产者通过 channel.basicPublish() 发送消息到交换机</p>
            </div>
            <div class="timeline-item">
                <h4 class="font-bold text-lg mb-2">2. 消息路由</h4>
                <p class="text-gray-600">RabbitMQ 将消息路由到相应的队列</p>
            </div>
            <div class="timeline-item">
                <h4 class="font-bold text-lg mb-2">3. 发布者确认</h4>
                <p class="text-gray-600">Broker 向生产者发送确认信号</p>
            </div>
            <div class="timeline-item">
                <h4 class="font-bold text-lg mb-2">4. 消息投递</h4>
                <p class="text-gray-600">消息从队列投递给消费者</p>
            </div>
            <div class="timeline-item">
                <h4 class="font-bold text-lg mb-2">5. 消息处理</h4>
                <p class="text-gray-600">消费者处理消息业务逻辑</p>
            </div>
            <div class="timeline-item">
                